<?php
class MemberController extends AppController {
	var $name = 'Member';
	var $components = array('Menu','Init');
	var $uses = array();

	function beforeFilter() {
		$this->Init->startup($this);
		$this->login = $this->Init->init();
		$this->Init->getKeyword();

		if(empty($this->login['User'])) {
			$this->redirect(array('controller' => 'login','action' => 'index'));
		}

		$_session = $this -> Session -> read();
		$this->loadModel('Hitcounter');
		$row = $this->Hitcounter->get(session_id());
		if ($row == 0) {
			$data = array(
				"session_id" => session_id(),
				"ref_url" => env("REQUEST_URI"),
				"ip_address" => env("REMOTE_ADDR"),
				"activity" => date("Y-m-d H:i:s")
			);
			$this->Hitcounter->save($data);
		}
		
		$this->set('activeNav', 'Home');
                $this->set('vipDiscount', $this->Session->read('discount_for_vip'));
	}

	function index() {
		$this->layout = 'inside';

		if (!$this->Session->read("lang")) {
			$lang = "vie";
		} else {
			$lang = $this->Session->read("lang");
		}

		Configure::write("Config.language", $lang);

		$this->loadModel('Order');
		$this->Order->loadDetail();

		$member = $this->Session->read('User.login');

		$menus = $this->Order->find('all', array(
				'conditions' => array('Order.member' => $member['id'])
		));
		$this->set('lang',$lang);
		$this->set('orders',$menus);
		$this->render('index');
	}

	function detail($id = null) {
		$this->layout = 'inside';

		$this->layout = 'inside';

		if (!$this->Session->read("lang")) {
			$lang = "vie";
		} else {
			$lang = $this->Session->read("lang");
		}

		Configure::write("Config.language", $lang);

		$this->loadModel('Order');
		$this->Order->loadDetail();

		$member = $this->Session->read('User.login');

		$menus = $this->Order->find('all', array(
				'recursive' => 2,
				'conditions' => array('Order.member' => $member['id'],'Order.id' => $id)
		));
		$this->set('lang',$lang);
		$this->set('orders',$menus);
	}
}
?>
